﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Data.SqlClient;
using System.Diagnostics;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        int a = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string str1 = System.Environment.CurrentDirectory;
            Console.WriteLine(str1);
            string path = "../../config/info.ini"; //@"C:\Users\Administrator\source\repos\ConsoleApp1\config\info.ini";
            string connectStr = "Data Source=.;Initial Catalog=cmxx;Integrated Security=True";
            //建立连接对象
            SqlConnection Sqlconn = new SqlConnection(connectStr);
            //打开连接
            Sqlconn.Open();
            //insertData(Sqlconn);
            Sqlconn.Close();
        }
        
        private void selectData(SqlConnection Sqlconn)
        {
            //为连接指定Command对象--查询数据
            SqlCommand thisCommand = Sqlconn.CreateCommand();
            thisCommand.CommandText = "select userName,userID,password from xx";
            //为指定的command对象执行DataReader
            SqlDataReader thisSqlDataReader = thisCommand.ExecuteReader();
            //循环读取查询到的数据值
            while (thisSqlDataReader.Read())
            {

                Console.WriteLine("{0} {1} {2}", thisSqlDataReader["userName"], thisSqlDataReader["userID"], thisSqlDataReader["password"]);
                string str1 = (string)thisSqlDataReader["userName"];
                string str2 = (string)thisSqlDataReader["password"];
                string str3 = textBox1.Text;
                string str4 = textBox2.Text;
                str1 = str1.Trim();
                str2 = str2.Trim();
                if (str3 == str1 && str4 == str2)
                {
                    a = 1;
                    break;
                }
            }
            //关闭读取
            thisSqlDataReader.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string str1 = System.Environment.CurrentDirectory;
            string connectStr = "Data Source=.;Initial Catalog=cmxx;Integrated Security=True";
            //建立连接对象
            SqlConnection Sqlconn = new SqlConnection(connectStr);
            //打开连接
            Sqlconn.Open();
                selectData(Sqlconn);
                
            
            Sqlconn.Close();
            if (a == 1)
            {
                Process process = new Process();
                process.StartInfo.FileName = @"..\..\..\..\总体框架\总体框架\总体框架\bin\Debug\.exe";
                process.Start();
                this.Hide();
            }
            else
            {
                MessageBox.Show("信息错误！！");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            dlck dl = new dlck();
            dl.Show();
           
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
